home *** CD-ROM | disk | FTP | other *** search
/ Whiteline: delta / whiteline CD Series - delta.iso / tools / lernen / dicionar / source / btree.def < prev    next >
Encoding:
Modula Definition  |  1995-11-25  |  5.5 KB  |  139 lines

  1. DEFINITION MODULE BTree;
  2.  
  3.  
  4. CONST  Order = 42; 
  5.        (* Mit dieser Ordnung erhält man TSIZE(PageType) von 512 k *)
  6.        nn = Order;
  7.        n = (nn DIV 2);
  8.        Empty= -1D;
  9.        TreeRoot=0D;
  10.  
  11.  
  12. TYPE (* TYPEn für den Bayer Baum *)
  13.  
  14.  
  15.      FileType = ( TheData, NumIndex, GerIndex, PorIndex );  
  16.      (* Unterscheidung zwischen Daten und IndexFiles             *)
  17.      (* und den verschiedenen IndexArten. Dieser AufzählungsTyp  *)
  18.      (* wird vor allem für die Querverweisliste bei multiplen    *)
  19.      (* Schlüsseln gebraucht (-> BaseType) => FileType so ordnen *)
  20.      (* daß bei Next : ARRAY [FileType] keine unnötigen Einträge *)
  21.      (* entstehen, d.h. zuerst alle IndexTypen die keine doppelten *)
  22.      (* Schlüssel zulassen und dann die anderen (oder so ... ) *)
  23.      
  24.  
  25.      KeyType = LONGCARD; (* Um diesen Typ zu ändern sind auch Anpassungen *)
  26.                     (* im  IMPLEMENTATION MODULE nötig !!! *)
  27.  
  28.      EntryType = ARRAY [0..43] OF CHAR;
  29.      
  30.      DataType = RECORD
  31.            Inhalt : ARRAY[0..4] OF EntryType;
  32.            Flags  : ARRAY [0..5] OF CHAR; 
  33.         (* 0..3 werden verwendet, 4,5 sind nur FüllBytes *)
  34.         (* um auf TSIZE(PageType) von 256 Bytes zu kommen *)
  35.         END(*RECORD*);
  36.  
  37.      DataPtr = LONGINT; (* Zeigt auf die Lage der Daten im File *)
  38.      
  39.                         (* Wenn man DataPtr bzw. PagePtr auf INTEGER *)
  40.                         (* ändern möchte sind einige Änderungen im  *)
  41.                         (* IMPLEMENTATION MODULE notwendig! *)
  42.                         
  43.      PagePtr = LONGINT; (* Position einer Seite im File *)
  44.  
  45.      KeyArray =  ARRAY [NumIndex..PorIndex] OF KeyType;
  46.      
  47.      BaseType = RECORD
  48.           Flag : BOOLEAN;
  49.           Next : ARRAY [GerIndex..PorIndex] OF DataPtr;
  50.           (* Querverweisliste (doppelt verkettet) für die Verwendung *)
  51.           (* von mehreren Einträgen pro Schlüssel *)
  52.           Prev : ARRAY [GerIndex..PorIndex] OF DataPtr;
  53.           Key  : KeyArray;
  54.           (*Key  : ARRAY [NumIndex..PorIndex] OF KeyType;*)
  55.           (* In diesem Feld werden sämtliche Schlüssel untergebracht *)
  56.           Data : DataType;
  57.         END(*RECORD*);
  58.  
  59.      ItemType = RECORD
  60.            Key        : KeyType;
  61.            RecordNr : DataPtr;
  62.            Ptr        : PagePtr;
  63.         END(*RECORD*);
  64.  
  65.      PageType = RECORD
  66.            Flag : BOOLEAN;
  67.            Anz    : CARDINAL;
  68.            Ptr0 : PagePtr;
  69.            Item : ARRAY [1..nn] OF ItemType;
  70.         END(*RECORD*);
  71.  
  72.  
  73.      FileOf = RECORD 
  74. (* Dieser Typ schleppt so ziemlich alles mit sich rum *)
  75. (* was für die Verwaltung der Datei interressant ist *)
  76.          Name : ARRAY [0..127] OF CHAR; 
  77.          (* Datei-Name *)
  78.          Handle : INTEGER; 
  79.          (* GEMDOS- Filehandle *)
  80.          CASE Type : FileType OF 
  81.          (* Je Nachdem ob es sich um ein Daten oder IndexFile *)
  82.          (* handelt Pointer auf unterschiedliche Typen        *)
  83.          (* Außerdem werden durch den Eintrag im TAG-Feld die *)
  84.          (* verschiedenen Querverweislisten verwaltet         *)
  85.                     TheData : RecordPtr : POINTER TO BaseType;
  86.                     ELSE     RecordPtr1 : POINTER TO PageType;
  87.                    END(*CASE*);
  88.          RecordSize : LONGINT; (* LONG(TSIZE(Inhalt)) *) 
  89.          (* Länge eines Records *)
  90.          Current : LONGINT; 
  91.          Last : LONGINT; (* PagePtr bzw DataPtr *) 
  92.          (* Letzter Eintrag in der Datei                  *) 
  93.          (* gibt gleichzeitig die Dateigröße in Records an *)
  94.                  MultipleKeys : BOOLEAN; 
  95.                  (* Flag ob mehrere Einträge unter einem Schlüssel erlaubt sind *)
  96.          END(*RECORD*);
  97.  
  98.     PrintDataProc = PROCEDURE( DataType);     
  99.  
  100. (* for internal use only :   *)
  101.  
  102. PROCEDURE Get( VAR File : FileOf; Pos : LONGINT);
  103. PROCEDURE Put( VAR File : FileOf; Pos : LONGINT);
  104. (*
  105. PROCEDURE FileLength(FileName : ARRAY OF CHAR; length : LONGINT) :BOOLEAN;
  106.   *)
  107.   
  108.   
  109.  
  110. PROCEDURE Create(VAR File : FileOf); (* Eine neue Datei anlegen. Ist eine Datei dieses Namens schon vorhanden wird sie gelöscht *)
  111. PROCEDURE Start(VAR File : FileOf); (* Datei Öfnen. Die Datei muß vorhanden sein !!! *)
  112. PROCEDURE Close(VAR File: FileOf);  (* Datei Schließen. Wichtig sonst gehen alle Daten verloren !!*)
  113.  
  114. PROCEDURE PutData(VAR DataBase : FileOf; Data : DataType;  Reference : DataPtr);
  115. PROCEDURE GetData(VAR DataBase : FileOf; VAR Data : DataType; VAR Keys : KeyArray; Reference :DataPtr);
  116.  
  117. PROCEDURE AddKey(VAR Index, DataBase : FileOf; NewKey : KeyType; Reference : DataPtr): BOOLEAN;
  118. PROCEDURE AddData( VAR DataBase : FileOf; NewData : DataType) : DataPtr;
  119.  
  120. PROCEDURE Delete(VAR Index, DataBase : FileOf; Key : KeyType; VAR DataPointer : DataPtr): BOOLEAN;
  121.  
  122. PROCEDURE SearchPtr(VAR Index, DataBase : FileOf; Page : PagePtr; Key : KeyType; VAR found : BOOLEAN) : DataPtr;
  123.  
  124. PROCEDURE SearchFirst(VAR Index, DataBase : FileOf; Key : KeyType; VAR Data : DataType; VAR Keys : KeyArray): BOOLEAN;
  125.  
  126. PROCEDURE SearchNext(VAR Index, DataBase : FileOf; VAR Data : DataType; VAR Keys : KeyArray) : BOOLEAN;
  127. PROCEDURE SearchPrevious(VAR Index, DataBase : FileOf; VAR Data : DataType;VAR Keys : KeyArray) : BOOLEAN;
  128. (*   Suche bei Schlüsselgleichheit  *)
  129.  
  130. PROCEDURE First(VAR Index, DataBase : FileOf; VAR Key : KeyType; VAR Data : DataType; VAR Keys : KeyArray);
  131. PROCEDURE Last (VAR Index, DataBase : FileOf; VAR Key : KeyType; VAR Data : DataType; VAR Keys : KeyArray);
  132.  
  133. PROCEDURE Next(VAR Index, DataBase : FileOf; Key : KeyType; VAR NextKey : KeyType; VAR NextData: DataType; VAR Keys : KeyArray) : BOOLEAN;
  134. PROCEDURE Previous(VAR Index, DataBase : FileOf;  Key : KeyType; VAR NextKey : KeyType; VAR NextData: DataType; VAR Keys : KeyArray) : BOOLEAN;
  135.  
  136. PROCEDURE PrintTree(VAR Index, DataBase : FileOf; Tree : PagePtr; Tiefe : CARDINAL; OutProc : PrintDataProc);
  137.  
  138. END BTree.
  139.